<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>login system</title>

    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="apple-touch-icon" href="apple-touch-icon.png">

    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="css/fontAwesome.css">
    <link rel="stylesheet" href="css/light-box.css">
    <link rel="stylesheet" href="css/templatemo-style.css">

    <link href="https://fonts.googleapis.com/css?family=Kanit:100,200,300,400,500,600,700,800,900" rel="stylesheet">

    <script src="js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"></script>
</head>

<body>

<nav>
    <div class="logo">
        <a href="/">返回<em>大厅</em></a>
    </div>
    <div class="menu-icon">
        <span></span>
    </div>
</nav>

<div class="page-heading">
    <div class="container">
        <div class="heading-content">
            <h1>login <em>system</em></h1>
        </div>
    </div>
</div>


<div class="blog-entries">
    <div class="container">
        <div class="col-md-2"></div>
        <div class="col-md-4"><img src="/img/login.jpg" width="330"
                                   height="280"></div>
        <div class="col-md-3">

            <form>
                <div class="form-group">
                    <input type="text" class="form-control" id="tel" name="tel" placeholder="手机号码">
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" id="password" name="password" placeholder="密码">
                </div>
                <div class="form-group">
                    <div class="col-md-4">
                        <p class="inner"><a href="toregister" rel="nofollow">快速注册</a></p>
                    </div>
                    <div class="col-md-4">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
                    </div>
                    <div class="col-md-4">
                        <p class="inner"><a href="/toarticle" rel="nofollow">游客登录</a></p>
                    </div>
                </div>
                <input type="button" id="submit" class="btn btn-default btn-lg btn-block" value="登陆"/>

            </form>
        </div>
        <div class="col-md-3"></div>
    </div>
</div>



<!-- Modal button -->
<div class="popup-icon">
    <button id="modBtn" class="modal-btn"><img src="img/contact-icon.png" alt=""></button>
</div>

<!-- Modal -->
<div id="modal" class="modal">
    <!-- Modal Content -->
    <div class="modal-content">
        <!-- Modal Header -->
        <div class="modal-header">
            <div id="unlogin">
                <h3 class="header-title">欢迎使用老杨的系统</h3>
                <br><br>
                <h4><a href="/tologin">点我登陆</a></h4>
                <br><br>
                <h4>没有账号？</h4>
                <br><br>
                <h4><a href="/toregister">点我注册</a></h4>
            </div>
            <div class="close-btn"><img src="img/close_contact.png" alt=""></div>
        </div>

    </div>
</div>

<section class="overlay-menu">
    <div class="container">
        <div class="row">
            <div class="main-menu">
                <ul>
                    <li>
                        <a href="/">系统首页</a>
                    </li>

                    <li>
                        <a href="/toarticle">所有文章</a>
                    </li>
                    <li>
                        <a href="/tomyarticle">我的文章</a>
                    </li>
                    <li>
                        <a href="/topermission">权限管理</a>
                    </li>
                    <li>
                        <a href="/tologin">登陆</a>
                    </li>
                    <li>
                        <a href="/toregister">注册</a>
                    </li>
                    <li>
                        <a href="/tologout">登出</a>
                    </li>
                </ul>
                <p>may you happy to use laoyang's bbs</p>
            </div>
        </div>
    </div>
</section>

<script src="https://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.min.js"><\/script>')</script>

<script src="js/vendor/bootstrap.min.js"></script>

<script src="js/plugins.js"></script>
<script src="js/main.js"></script>

<script>


    function func() {
        //验证用户是否已经注册过
        var tel = $("#tel").val();//获取表单元素值
        var password = $("#password").val();

        var tel = document.getElementById('tel').value;
        if(tel==""){
            alert("手机号不能为空！");
            //window.location.href="register.html";
            return false;
        }

        if (!(/^1[34578]\d{9}$/.test(tel))) {
            alert("手机号输入错误");
            return false;
        }
        if(password=="")
        {
            alert("密码不能为空！");
            return false;
        }
        if(password.length<4){
            alert("密码不能少于4位！");
            return false;
        }
        return true;
    }

    $("#submit").on("click", function() {
        if (!func()) {
            console.log("!!!!!!");
            return false;
        }
        var tel = $("#tel").val();//获取表单元素值
        var password = $("#password").val();
        var data = {
            tel : tel,
            password : password
        };
        $.ajax({
            type : "POST",
            url : "login",
            data : data,
            dataType : 'json',
            success : function(msg) {
                if ("00"==msg.errorCode) {
                    console.log("success");
                    window.location.href = "/toarticle";
                } else if("11"==msg.errorCode) {
                    alert("该手机号码不存在！");
                    console.log("该手机号码不存在！");
                    return false;
                }else if("22"==msg.errorCode){
                    alert("密码输入错误，错误输入三次后您的账户将会被锁定！");
                    return false;
                }
                else if("33"==msg.errorCode){
                    alert("您由于错误登陆次数太多，系统已将您的账户锁定，请在三分钟后重新登录！");
                    return false;
                }
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                // 状态码
                console.log(XMLHttpRequest.status);
                // 状态
                console.log(XMLHttpRequest.readyState);
                // 错误信息
                console.log(textStatus);
            }

        });
    });
</script>

</body>
</html>